Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP 8.1: Added support for enum keyword #3478

Merged
merged 1 commit into from
Jan 16, 2022

Conversation

kukulich
Copy link
Contributor

@kukulich kukulich commented Nov 19, 2021

Fixes #3474

@kukulich kukulich changed the title PHP 8.1: Added support for "enum" keyword PHP 8.1: Added support for enum keyword Nov 19, 2021
Copy link
Contributor

@jrfnl jrfnl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kukulich 👋🏻 Thank you for creating this PR. Looking good!

I've left some comments inline to think over. Hope it helps.

src/Tokenizers/PHP.php Show resolved Hide resolved
src/Util/Tokens.php Show resolved Hide resolved
tests/Core/Tokenizer/EnumTest.inc Outdated Show resolved Hide resolved
@kukulich kukulich force-pushed the php81-enum-keyword branch 2 times, most recently from a86c6de to d709d56 Compare November 19, 2021 20:58
src/Tokenizers/PHP.php Outdated Show resolved Hide resolved
@jrfnl
Copy link
Contributor

jrfnl commented Nov 19, 2021

Thanks for the update @kukulich, left one more comment. Other that that, 👍🏻

Copy link
Contributor

@jrfnl jrfnl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't verified against the RFC, I trust @kukulich will have done that, but PR-wise, this looks to cover all the bases 💯

@kukulich kukulich mentioned this pull request Nov 20, 2021
8 tasks
@kukulich kukulich force-pushed the php81-enum-keyword branch 2 times, most recently from 42551e5 to eb27ac3 Compare November 20, 2021 11:05
Copy link
Contributor

@jrfnl jrfnl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, still found some more issues to be addressed.

tests/Core/Tokenizer/EnumTest.php Outdated Show resolved Hide resolved
*
* @return void
*/
public function testEnums($testMarker, $expectedScopeOpenerLine, $expectedScopeCloserLine)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wondering - why test the line and not the actual token position (in relation to the keyword token) ?
I realize the latter is more fiddly for setting up the tests, but it's also much more precise.

In other tests, this has been done by the data provider providing an offset and the token position then being calculated by $expectedOpener = $enum + $openerOffset;.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modified.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you modified it for scope opener, but removed the check for scope closer ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added now.

src/Util/Tokens.php Outdated Show resolved Hide resolved
@kukulich kukulich force-pushed the php81-enum-keyword branch 3 times, most recently from 3e94231 to bca788c Compare November 20, 2021 14:35
@gsherwood gsherwood added this to Idea Bank in PHPCS v3 Development via automation Nov 21, 2021
@gsherwood gsherwood added this to the 3.7.0 milestone Nov 21, 2021
@kukulich kukulich force-pushed the php81-enum-keyword branch 3 times, most recently from a7a0128 to 106eba3 Compare December 17, 2021 07:34
@tarlepp
Copy link

tarlepp commented Jan 9, 2022

What is the current state of this one?

@kukulich
Copy link
Contributor Author

Rebased on master.

gsherwood added a commit that referenced this pull request Jan 16, 2022
@gsherwood gsherwood merged commit f236c6a into squizlabs:master Jan 16, 2022
PHPCS v3 Development automation moved this from Idea Bank to Ready for Release Jan 16, 2022
$tokens = self::$phpcsFile->getTokens();

$target = $this->getTargetToken($testMarker, [T_ENUM, T_STRING], $testContent);
$this->assertSame(T_STRING, $tokens[$target]['code']);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Due to the way namespaces are tokenized in 4.0 (they become T_NAME_RELATIVE or T_NAME_QUALIFIED) I had to reverse this logic in the 4.0 branch to use assertNotSame(T_ENUM...). I didn't make the same change in master.

@gsherwood
Copy link
Member

Thanks a lot for this PR. I really appreciate the effort you're putting in to add support for 8.1 features to PHPCS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
PHPCS v3 Development
Ready for Release
Development

Successfully merging this pull request may close these issues.

PHP 8.1 enum not recognized
4 participants